function modify_leaving_detail_1(leaving_id, token) {
    httpRequest("http://172.27.71.125:7402/leave/api/getexaminingdetail", JSON.stringify({"token": token, "leavingId": leaving_id}),
        response => {
            const name = document.getElementById("name");
            const college = document.getElementById("college");
            const square = document.getElementById("square");
            const sex = document.getElementById("sex");
            const code = document.getElementById("code");
            const phone = document.getElementById("phone");
            const area = document.getElementById("area");
            const state = document.getElementById("state");
            const time_start = document.getElementById("time-start");
            const time_end = document.getElementById("time-end");
            const reason_radios = document.getElementsByName("reason-radio");
            const reason_text = document.getElementById("reason-text");
            const teacher_view = document.getElementById("teacher-view");
            const teacher_view_name = document.getElementById("teacher-view-name");
            const teacher_view_time = document.getElementById("teacher-view-time");
            const institute_view_container = document.getElementById("institute-view-container");
            const institute_view = document.getElementById("institute-view");
            const institute_view_name = document.getElementById("institute-view-name");
            const institute_view_time = document.getElementById("institute-view-time");
            const institute_background = document.getElementById("institute-background");

            const res = JSON.parse(response)["result"];
            name.value = res[0]["name"];
            college.value = res[0]["college"];
            square.value = res[0]["square"];
            sex.value = res[0]["sex"];
            code.value = res[0]["student_code"];
            phone.value = res[0]["telephone"];
            state.innerText = res[1]["leaving_state"];
            area.value = res[1]["leaving_destination"];
            time_start.value = res[1]["leaving_start"];
            time_end.value = res[1]["leaving_end"];
            reason_radios[res[1]["leaving_reason"] - 1].checked = true;
            reason_text.value = res[1]["leaving_detail"];
            if (res[1]["leaving_type"] === "大于十天") {
                institute_view_container.removeAttribute("hidden");
            }
            if (res.length > 3) {
                institute_view.innerText = res[3]["examine_result"] + "！" + res[3]["examine_comment"];
                institute_view_name.innerText = res[3]["teacher_name"];
                institute_view_time.innerText = res[3]["examine_date"];
                if (res[3]["examine_result"] === "不同意") {
                    institute_background.setAttribute("hidden", null);
                }
            } else {
                institute_view_name.setAttribute("hidden", null);
                institute_view_time.setAttribute("hidden", null);
                institute_background.setAttribute("hidden", null);
            }
            if (res.length > 2) {
                teacher_view.innerText = res[2]["examine_result"] + "！" + res[2]["examine_comment"];
                teacher_view_name.innerText = res[2]["teacher_name"];
                teacher_view_time.innerText = res[2]["examine_date"];
            } else {
                teacher_view_name.setAttribute("hidden", null);
                teacher_view_time.setAttribute("hidden", null);
            }
        });
}

function modify_leaving_detail(leaving_id, token) {
    httpRequest("http://172.27.71.125:7402/leave/api/getleavingdetail", JSON.stringify({
            "token": token,
            "leavingId": leaving_id
        }),
        response => {
            const name = document.getElementById("name");
            const college = document.getElementById("college");
            const square = document.getElementById("square");
            const sex = document.getElementById("sex");
            const code = document.getElementById("code");
            const phone = document.getElementById("phone");
            const area = document.getElementById("area");
            const state = document.getElementById("state");
            const time_start = document.getElementById("time-start");
            const time_end = document.getElementById("time-end");
            const reason_radios = document.getElementsByName("reason-radio");
            const reason_text = document.getElementById("reason-text");
            const teacher_view = document.getElementById("teacher-view");
            const teacher_view_name = document.getElementById("teacher-view-name");
            const teacher_view_time = document.getElementById("teacher-view-time");
            const institute_view_container = document.getElementById("institute-view-container");
            const institute_view = document.getElementById("institute-view");
            const institute_view_name = document.getElementById("institute-view-name");
            const institute_view_time = document.getElementById("institute-view-time");
            const institute_background = document.getElementById("institute-background");

            const res = JSON.parse(response)["result"];
            name.value = res[0]["name"];
            college.value = res[0]["college"];
            square.value = res[0]["square"];
            sex.value = res[0]["sex"];
            code.value = res[0]["student_code"];
            phone.value = res[0]["telephone"];
            state.innerText = res[1]["leaving_state"];
            area.value = res[1]["leaving_destination"];
            time_start.value = res[1]["leaving_start"];
            time_end.value = res[1]["leaving_end"];
            reason_radios[res[1]["leaving_reason"] - 1].checked = true;
            reason_text.value = res[1]["leaving_detail"];
            if (res[1]["leaving_type"] === "大于十天") {
                institute_view_container.removeAttribute("hidden");
            }
            if (res.length > 3) {
                institute_view.innerText = res[3]["examine_result"] + "！" + res[3]["examine_comment"];
                institute_view_name.innerText = res[3]["teacher_name"];
                institute_view_time.innerText = res[3]["examine_date"];
            } else {
                institute_view_name.setAttribute("hidden", null);
                institute_view_time.setAttribute("hidden", null);
                institute_background.setAttribute("hidden", null);
            }
            if (res.length > 2) {
                teacher_view.innerText = res[2]["examine_result"] + "！" + res[2]["examine_comment"];
                teacher_view_name.innerText = res[2]["teacher_name"];
                teacher_view_time.innerText = res[2]["examine_date"];
            } else {
                teacher_view_name.setAttribute("hidden", null);
                teacher_view_time.setAttribute("hidden", null);
            }
        });
}

window.onload = () => {
    const queryString = window.location.search.substring(1);
    const t = queryString.split("&");
    const queryDict = {}
    for (let i = 0; i < t.length; i++) {
        let ti = t[i].split("=");
        queryDict[ti[0]] = ti[1];
    }
    if (t.length < 3 || queryDict["leaving_id"] == null || queryDict["token"] == null || queryDict["identity"] == null)
        urlReplace("login.html");
    if (queryDict["identity"] === "0") {
        modify_leaving_detail(queryDict["leaving_id"], queryDict["token"]);
    } else {
        modify_leaving_detail_1(queryDict["leaving_id"], queryDict["token"]);
    }
};
